Error: '$viewMap[...]' is null or not an object
Posted
by DK
on Stack Overflow
See other posts from Stack Overflow
or by DK
Published on 2009-12-15T09:45:14Z
Indexed on
2010/04/01
16:03 UTC
Read the original article
Hit count: 218
jQuery
|JavaScript
My jQuery/Javascript knowledge is limited I'm afraid. I have a "how did you hear about us" dropdown on a form. However, I get the following Javascript error on change:
Error: '$viewMap[...]' is null or not an object
My dropdown looks like this:
<select onchange="setSourceID(this.value)" name="sourceID" id="sourceID" class="required">
<option value="" selected="selected">Please choose…</option>
<option value="National Paper">National Paper</option>
<option value="Magazine">Magazine</option>
<option value="Regional Paper">Regional Paper</option>
<option value="9682">Internet Search</option>
<option value="9684">Recommendation</option>
<option value="9683">Other</option>
</select>
<!-- some additional dropdowns below that appear based on what's selected above -->
<select onchange="setSourceID(this.value)" name="referrerName[]" id="referrer1" class="smartField">
<option value="" selected="selected">Please choose…</option>
<option value="The Times">The Times</option>
etc...
</select>
and so on...
My Javascript looks like this:
$(document).ready(function() {
$('.smartField').hide();
$.viewMap = {
'' : $([]),
'National Paper' : $('#referrer1'),
'Magazine' : $('#referrer2'),
'Regional Paper' : $('#referrer3')
//'Internet Search' : $('#referrer4'),
//'Recommendation' : $('#referrer5'),
//'Other' : $('#referrer6')
};
$("#sourceID").bind(($.browser.msie ? "click" : "change"), function () {
$.each($.viewMap, function() { this.hide(); }); // hide all
$.viewMap[$(this).val()].show(); // show current
});
});
Does anybody have any idea where I'm going wrong? Any help very much appreciated.
© Stack Overflow or respective owner